package com.example.baseui2.recycleVIew

import android.graphics.Bitmap
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.BindingAdapter
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import com.example.baseui2.R
import com.example.baseui2.bean.RecycleViewBean
import com.whr.baseui.BR
import com.whr.baseui.mvvm.BaseBindingRvAdapter
import com.whr.baseui.mvvm.BaseBindingViewHolder

class RecycleViewAdapter : BaseBindingRvAdapter<RecycleViewBean>(){
    companion object{
        @BindingAdapter("whr:src")
        @JvmStatic
        fun setSrc(view: ImageView, resId: Int) {
            view.setImageResource(resId)
        }
        @BindingAdapter("whr:toStr")
        @JvmStatic
        fun setStrText(view: TextView, any: Any?) {
            view.setText(any?.toString())
        }
    }

    override fun onBindViewHolder(holder: BaseBindingViewHolder, position: Int) {
        var binding : ViewDataBinding = holder.dataBinding
        binding.setVariable(BR.recycleViewBean,data.get(position))
    }

    override fun getItemViewType(position: Int): Int {
        return R.layout.item_recycle_view
    }

}